package kr.co.bettersoftportal.site.management.controller;


import kr.co.bettersoftportal.site.domain.Comment;
import kr.co.bettersoftportal.site.domain.Member;
import kr.co.bettersoftportal.site.domain.NoticeBoard;
import kr.co.bettersoftportal.site.domain.UploadFile;
import kr.co.bettersoftportal.site.management.service.BettersoftPortalService;
import kr.co.bettersoftportal.site.management.service.CommentService;
import kr.co.bettersoftportal.site.management.service.NoticeBoardService;
import kr.co.bettersoftportal.site.management.util.BettersoftPortalCommon;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * CheckMileage Controller : 회원 및 가맹점 관리 사이트 기능
 */
public class NoticeboardController extends MultiActionController {



    // SLF4J Logging
    private Logger logger = LoggerFactory.getLogger(NoticeboardController.class);

    //    @Autowired
//    private BettersoftPortalService bettersoftPortalService = null;
    @Autowired
    private LocaleResolver localeResolver = null;

    @Autowired
    private BettersoftPortalService bettersoftPortalService = null;

    @Autowired
    private CommentService commentService = null;

    @Autowired
    private NoticeBoardService noticeBoardService = null;



/**
     * Notice Board 리스트 출력
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setActivate_yn("Y");
        board.setWriter_id(""); //검색값 초기화


        /**
         * Null 에러 방지용 공백 전환
         */
        if(board.getTitle() == null){
            board.setTitle("");
        }

        if(board.getWriter_id() == null){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name() == null){
            board.setWriter_nick_name("");
        }

        if(board.getContent() == null){
            board.setContent("");
        }


        logger.info("noticeBoardList");
        logger.info("title      : {}", board.getTitle());
        logger.info("id         : {}", board.getWriter_id());
        logger.info("nickName   : {}", board.getWriter_nick_name());
        logger.info("content    : {}", board.getContent());
        logger.info("nextTarget : {}", request.getParameter("nextTarget"));

        if(board.getTitle().equals(null)){
            board.setTitle("");
        }

        if(board.getWriter_id().equals(null)){
            board.setWriter_id("");
        }

        if(board.getWriter_nick_name().equals(null)){
            board.setWriter_nick_name("");
        }

        if(board.getContent().equals(null)){
            board.setContent("");
        }

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board);
        String totalCount = noticeBoardService.getTotalCountBySearchword(board);
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());


        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }

    /**
     * Notice Board 글 수정 페이지로 이동
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    public ModelAndView noticeBoardUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception{

        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setActivate_yn("Y");

//        logger.info("noticeBoardUpdate");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        String boardno = board.getNotice_board_no();

        NoticeBoard tempBoard = new NoticeBoard();

        tempBoard = noticeBoardService.getBoardByNo(boardno);
        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        ModelAndView mav = new ModelAndView();

        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        return mav;
    }

    /**
     * Notice Board 글 수정 실행
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardUpdateAction(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());
        board.setModify_date(strDate);
        String result = "";

        String img_changed = request.getParameter("img_changed");
        if(img_changed.equals("no")){               // 파일 변경 없음 -> 이미지 제외한 업로드.
            result = noticeBoardService.updateBoardNotImage(board); // updateBoard 서비스를 호출 결과를 result 에 담는다
        }else if(img_changed.equals("yes")){        // 파일 변경 있음 -> 이미지 포함 업로드 실시.
            // 파일 업로드 시작
            MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request; // HttpServletRequest 를 MultipartHttpServletRequest 로 casting

            MultipartFile mpFile = mpRequest.getFile("fileUp"); // casting 된 request 에서 파일 얻어오기
            if(mpFile.isEmpty()){ // 첨부 파일이 있는지 검사. 없는 경우
                board.setAdd_file_yn("N");
            }else{                                  // 첨부파일 있는 경우.
                String uploadPath = request.getRealPath("/");
                String filePath = getServletContext().getRealPath("/upload/");
                UploadFile file = noticeBoardService.uploadFile(mpFile, uploadPath + "/upload/"); // 있다면 파일 업로드 서비스를 수행 (MultipartFile, 업로드 경로)
//                if(file.getContentType().contains("image")){ // 파일 형식을 검색 Image 형식이면 썸네일을 만든다
//                    File src = new File(uploadPath + "/upload/" + file.getTempFileName()); // 업로드된 이미지 원본 경로
//                }

                /**
                 * 첨부파일에 관련된 속성들을 도메인에 셋팅
                 */
                board.setAdd_file_yn("Y");
                board.setAdd_file_original_name(file.getFileName());
                board.setAdd_file_temp_name(file.getTempFileName());
                board.setAdd_file_content_type(file.getContentType());
                board.setAdd_file_size(file.getFileSize());
            }
            // 파일 업로드 끝

            result = noticeBoardService.updateBoard(board); // updateBoard 서비스를 호출 결과를 result 에 담는다
        }

        board.setActivate_yn("Y");

        logger.info("noticeBoardUpdateAction");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());

        //검색값 초기화
        board.setTitle("");
        board.setWriter_id("");
        board.setWriter_nick_name("");
        board.setContent("");

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView("redirect:./noticeBoardContent.do?&boardno=" + board.getNotice_board_no() + "&page=" + board.getCurrentPage() + "&token=" + board.getNotice_board_no() + "&title&writer_id&writer_nick_name&&content");
    }

    /**
     * Notice Board 글 작성 페이지로 이동
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardWrite(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setActivate_yn("Y");
        board.setHitcount("0");
        board.setReply_count("0");
        board.setVote("0");
        board.setNegative("0");
        board.setReport("0");

        logger.info("noticeBoardWrite");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
        logger.info("content   : {}", board.getContent());


        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());
        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }


    /**
     * Notice Board 글 작성 실행
     *
     * 첨부파일 경로 게시판 별로 다른 디렉토리 설정
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardWriteAction(HttpServletRequest request, HttpServletResponse response) throws Exception{

        NoticeBoard board = new NoticeBoard();
        bind(request, board);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());
        board.setRegister_date(strDate);

        logger.info("noticeBoardWriteAction");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        // 파일 업로드 시작
        MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request; // HttpServletRequest 를 MultipartHttpServletRequest 로 casting

        MultipartFile mpFile = mpRequest.getFile("fileUp"); // casting 된 request 에서 파일 얻어오기

        if(mpFile.isEmpty()){ // 첨부 파일이 있는지 검사
            board.setAdd_file_yn("N");
        }else{

            String uploadPath = request.getRealPath("/");
            UploadFile file = noticeBoardService.uploadFile(mpFile, uploadPath + "/upload/"); // 있다면 파일 업로드 서비스를 수행 (MultipartFile, 업로드 경로)
            /**
             * 첨부파일에 관련된 속성들을 도메인에 셋팅
             */
            board.setAdd_file_yn("Y");
            board.setAdd_file_original_name(file.getFileName());
            board.setAdd_file_temp_name(file.getTempFileName());
            board.setAdd_file_content_type(file.getContentType());
            board.setAdd_file_size(file.getFileSize());
        }
        // 파일 업로드 끝

        String result = "";

        board.setHitcount("0");
        board.setReply_count("0");
        board.setVote("0");
        board.setNegative("0");
        board.setReport("0");
        board.setActivate_yn("Y");

        result = noticeBoardService.writeBoard(board); // writeBoard 서비스를 호출 결과를 result 에 담는다

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView("redirect:/noticeBoardList.do?&title&writer_id&writer_nick_name&&content", "boardList", boardList);
    }

    /**
     * Notice Board 글삭제
     * activate_yn = n
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */

    public ModelAndView noticeBoardDelete(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        String result = "";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String strDate = df.format(new Date());
        board.setModify_date(strDate);

        board.setActivate_yn("N");

        logger.info("noticeBoardDelete");
        logger.info("title     : {}", board.getTitle());
        logger.info("id        : {}", board.getWriter_id());
        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());

        result = noticeBoardService.deleteBoard(board); // deleteBoard 서비스를 호출 결과를 result 에 담는다
        board.setActivate_yn("Y");
        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }

        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }

    /**
     * Notice Board 글내용 보기
     *
     * 첨부파일 add_file_yn 검사하여 있다면 다운로드 가능
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardContent(HttpServletRequest request, HttpServletResponse response) throws Exception{

        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        /**
         * Null 에러 방지용 공백 전환
         */
        if(request.getParameter("boardno") == null){
            return new ModelAndView("redirect:noticeBoardList.do");
        }

        if(request.getParameter("page") == null){
            return new ModelAndView("redirect:noticeBoardList.do");
        }


        logger.info("noticeBoardContent");
        logger.info("boardno     : {}", request.getParameter("boardno"));
        logger.info("page        : {}", request.getParameter("page"));
        

        board.setNotice_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        /**
         * 게시물 아래에 보여질 게시물 목록을 boardList 에 담아 넘긴다
         * 게시물 내용이 보여질 정보들은 notice_board_no 으로 검색해 받아와 board 에 담아 넘긴다.
         */

        board.setActivate_yn("Y");

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }



        // 줄바꿈 처리
        NoticeBoard tempBoard = new NoticeBoard();

        String tempContent;

        tempBoard = noticeBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.
        tempContent = tempBoard.getContent().replace("\r\n", "<br>"); // 게시물 부분을 임시 String 에 넣는다 줄바꿈 처리
        /**
         tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
         tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.
         *
         */
        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝

        HttpSession check = request.getSession(false);

        String sessionToken;
        String formToken;

        if((String)check.getAttribute("sessionToken") == null){
            sessionToken = "";
        }else{
            sessionToken = (String)check.getAttribute("sessionToken");
        }

        if(request.getParameter("token") == null){
            formToken = "";
        }else{
            formToken = request.getParameter("token");
        }




        // hitcount 증가
        int hitCount = Integer.parseInt(tempBoard.getHitcount());
        if(sessionToken.equals(formToken)){
            /**
             * request 로부터 넘어온 token 과 sessionToken 이 일치하면 hitcount를 증가하지 않는다.
             */

        }else{
            hitCount++;
            check.setAttribute("sessionToken", formToken);
            /**
             * hitcount 증가 후
             * 어느 페이지로부터 온 token 인지를 sessionToken 에 기록한다.
             * 같은 페이지에서 넘어왔다면 sessionToken 과 request 의 token 이 같기때문에 위의 if문이 실행된다.
             */

        }

        tempBoard.setHitcount(Integer.toString(hitCount));
        tempBoard.setNotice_board_no(request.getParameter("boardno"));

        String HitCountResult = noticeBoardService.updateHitCount(tempBoard);

        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }





        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("BETTERSOFTPORTAL_NOTICE_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        /**
         * List 에 담은 댓글 내용들 줄바꿈 처리 하기
         */
        for(int i=0;i<commentList.size();i++){
            comment = (Comment)commentList.get(i);
            comment.setContent(comment.getContent().replace("\r\n", "<br>"));
            commentList.set(i, comment);
        }


        ModelAndView mav = new ModelAndView();
        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }

    /**
     * Vote Method 게시물 추천 하기
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardVote(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setNotice_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        board.setActivate_yn("Y");

//        logger.info("noticeBoardVote");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }



        // 줄바꿈 처리
        NoticeBoard tempBoard = new NoticeBoard();

        String tempContent;

        tempBoard = noticeBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝

        //추천 업데이트
        int voteCount = Integer.parseInt(tempBoard.getVote());
        voteCount++;
        tempBoard.setVote(Integer.toString(voteCount));
        tempBoard.setNotice_board_no(request.getParameter("boardno"));

        String voteCountResult = noticeBoardService.updateVoteCount(tempBoard);


        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("BETTERSOFTPORTAL_NOTICE_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:noticeBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&token=" + request.getParameter("boardno") + "&title&writer_id&writer_nick_name&&content");
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }

    /**
     * Negative Method 게시물 비추천 하기
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardNegative(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setNotice_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        board.setActivate_yn("Y");

//        logger.info("noticeBoardNegative");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }



        // 줄바꿈 처리
        NoticeBoard tempBoard = new NoticeBoard();

        String tempContent;

        tempBoard = noticeBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝

        // 비추천 업데이트

        int negativeCount = Integer.parseInt(tempBoard.getNegative());
        negativeCount++;
        tempBoard.setNegative(Integer.toString(negativeCount));
        tempBoard.setNotice_board_no(request.getParameter("boardno"));

        String negativeCountResult = noticeBoardService.updateNegativeCount(tempBoard);

        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("BETTERSOFTPORTAL_NOTICE_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:noticeBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&token=" + request.getParameter("boardno") + "&title&writer_id&writer_nick_name&&content");
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }

    /**
     * Report Method 게시물 신고 하기
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView noticeBoardReport(HttpServletRequest request, HttpServletResponse response) throws Exception{
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

//        logger.info("noticeBoardReport");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        board.setNotice_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        board.setActivate_yn("Y");

        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }



        // 줄바꿈 처리
        NoticeBoard tempBoard = new NoticeBoard();

        String tempContent;

        tempBoard = noticeBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.

        tempContent = tempBoard.getContent(); // 게시물 부분을 임시 String 에 넣는다
        tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
        tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.

        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝

        //신고 업데이트
        int reportCount = Integer.parseInt(tempBoard.getReport());
        reportCount++;
        tempBoard.setReport(Integer.toString(reportCount));
        tempBoard.setNotice_board_no(request.getParameter("boardno"));

        String reportCountResult = noticeBoardService.updateReportCount(tempBoard);

        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }

        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("BETTERSOFTPORTAL_NOTICE_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName("redirect:noticeBoardContent.do?boardno=" + request.getParameter("boardno") + "&page=" + request.getParameter("page") + "&token=" + request.getParameter("boardno") + "&title&writer_id&writer_nick_name&&content");
        mav.addObject("baord", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }


    /**
     * notice Board File Download Controller
     * download.do 에서 GET 방식으로
     * 서버에 UUID 를 이용해서 바뀌어 들어간 add_file_temp_name 과
     * 원래 파일의 파일명인 add_file_original_name 을 파라미터로 받아와
     * 다운로드를 구현한다.
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws Exception{

        String filePath = request.getRealPath("/") + "/upload/" + request.getParameter("tFileName"); // 서버의 저장경로 + 물리 파일명 받아와 경로를 설정
        String o_fileName = request.getParameter("oFileName"); // 원래 파일명 받아오기

//        logger.info("download");
//        logger.info("tFileName : {}", request.getParameter("tFileName"));
//        logger.info("oFileName : {}", request.getParameter("oFileName"));


        File file = new File(filePath); // response 할 파일 객체 생성

        response.setContentType("application/octet-stream"); // 반드시 해줘야됨
        response.setContentLength((int)file.length());

        String userAgent = request.getHeader("User-Agent");


        boolean ie = userAgent.indexOf("MSIE") > -1; // Internet Explorer 검사

        String fileName = null;

        if(ie){

            fileName = URLEncoder.encode(file.getName(), "utf-8");

        } else {

            fileName = new String(file.getName().getBytes("utf-8"));

        }// end if;


        response.setHeader("Content-Disposition", "attachment; filename=" + o_fileName); // 파일의 본래 이름
        response.setHeader("Content-Transfer-Encoding", "binary");

        // 다운로드 시작
        OutputStream out = response.getOutputStream();
        FileInputStream fis = null;

        try {

            fis = new FileInputStream(file);

            FileCopyUtils.copy(fis, out);


        } catch(Exception e){

            e.printStackTrace();

        }finally{

            if(fis != null){

                try{
                    fis.close();
                }catch(Exception e){}
            }

        }
        // 다운로드 끝

        out.flush();


        return null;

    }

    /**
     * Mobile Notice Board 리스트 출력
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView mNoticeBoardList(HttpServletRequest request, HttpServletResponse response) throws Exception {
        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setActivate_yn("Y");
        board.setWriter_id(""); //검색값 초기화
        board.setWriter_nick_name("");
        board.setTitle("");
        board.setContent("");

//        logger.info("mobileNoticeBoardList");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());




        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board);
        String totalCount = noticeBoardService.getTotalCountBySearchword(board);
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_year = full_date.substring(0,4);
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());
        return new ModelAndView(request.getParameter("nextTarget"), "boardList", boardList);
    }

    /**
     * Notice Board 글내용 보기
     *
     * 첨부파일 add_file_yn 검사하여 있다면 다운로드 가능
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    public ModelAndView mNoticeBoardContent(HttpServletRequest request, HttpServletResponse response) throws Exception{

        NoticeBoard board = new NoticeBoard();
        bind(request, board);

        board.setNotice_board_no(request.getParameter("boardno")); // GET 방식으로 받아온 boardno 파라미터를 도메인에 셋팅
        board.setCurrentPage(Integer.parseInt(request.getParameter("page"))); // GET 방식으로 받아온 page 파라미터 CurrenPage 에 셋팅


        /**
         * 게시물 아래에 보여질 게시물 목록을 boardList 에 담아 넘긴다
         * 게시물 내용이 보여질 정보들은 notice_board_no 으로 검색해 받아와 board 에 담아 넘긴다.
         */

        board.setActivate_yn("Y");
        board.setWriter_id(""); //검색값 초기화
        board.setWriter_nick_name("");
        board.setTitle("");
        board.setContent("");

//        logger.info("mobileNoticeBoardContent");
//        logger.info("title     : {}", board.getTitle());
//        logger.info("id        : {}", board.getWriter_id());
//        logger.info("nickName  : {}", board.getWriter_nick_name());
//        logger.info("content   : {}", board.getContent());


        java.util.List boardList = noticeBoardService.getBoardListBySearchword(board); // Board List 꺼내와 List 에 담기
        String totalCount = noticeBoardService.getTotalCountBySearchword(board); // 꺼내온 갯수
        // 시간 분할.
        NoticeBoard tmpboard= new NoticeBoard();
        String full_date= "";
        String date_part_year = "";
        String date_part_month = "";
        String date_part_day = "";
        String date_part_hour = "";
        String date_part_minute = "";
        for(int i =0; i<boardList.size(); i++){
            tmpboard = (NoticeBoard)boardList.get(i);
            full_date = tmpboard.getModify_date();
            if(full_date!=null && full_date.length()>16){       // yyyy-mm-dd hh:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
                date_part_month = full_date.substring(5,7);
                date_part_day = full_date.substring(8,10);
                date_part_hour = full_date.substring(11,13);
                date_part_minute = full_date.substring(14,16);
                ((NoticeBoard) boardList.get(i)).setDate_part_year(date_part_year);
                ((NoticeBoard) boardList.get(i)).setDate_part_month(date_part_month);
                ((NoticeBoard) boardList.get(i)).setDate_part_day(date_part_day);
                ((NoticeBoard) boardList.get(i)).setDate_part_hour(date_part_hour);
                ((NoticeBoard) boardList.get(i)).setDate_part_minute(date_part_minute);
            }
        }



        // 줄바꿈 처리
        NoticeBoard tempBoard = new NoticeBoard();

        String tempContent;

        tempBoard = noticeBoardService.getBoardByNo(request.getParameter("boardno")); // 임시 도메인에 받아온 도메인 리스트에서 첫번째를 주입한다.
        tempContent = tempBoard.getContent().replace("\r\n", "<br>"); // 게시물 부분을 임시 String 에 넣는다 줄바꿈 처리
        /**
         tempContent.replaceAll("\n", "<br>"); // 줄바꿈 처리를 한다.
         tempContent.replaceAll("\u0020", "&nbsp;"); // 스페이스바 공백 처리를 한다.
         *
         */
        tempBoard.setContent(tempContent); // 임시 String 을 임시 객체에 다시 넣는다

        // 줄바꿈 처리 끝

        // hitcount 증가
        int hitCount = Integer.parseInt(tempBoard.getHitcount());
        hitCount++;
        tempBoard.setHitcount(Integer.toString(hitCount));
        tempBoard.setNotice_board_no(request.getParameter("boardno"));

        String HitCountResult = noticeBoardService.updateHitCount(tempBoard);


        // date -> 년, 월, 일, 시, 분 으로 나누어 저장.
        full_date = tempBoard.getModify_date();
        if(full_date!=null && full_date.length()>16){       // yyyy-MM-dd HH:mm:ss  0~4. 5~7, 8~10,  / 11~13, 14~16  (중간 공백은 Skip 됨)
            date_part_year = full_date.substring(0,4);
            date_part_month = full_date.substring(5,7);
            date_part_day = full_date.substring(8,10);
            date_part_hour = full_date.substring(11,13);
            date_part_minute = full_date.substring(14,16);
//            logger.info("date_part_year   : {}", date_part_year);
//            logger.info("date_part_month   : {}", date_part_month);
//            logger.info("date_part_day   : {}", date_part_day);
//            logger.info("date_part_hour   : {}", date_part_hour);
//            logger.info("date_part_minute   : {}", date_part_minute);
            tempBoard.setDate_part_year(date_part_year);
            tempBoard.setDate_part_month(date_part_month);
            tempBoard.setDate_part_day(date_part_day);
            tempBoard.setDate_part_hour(date_part_hour);
            tempBoard.setDate_part_minute(date_part_minute);
        }




        /**
         *
         * Comment 담아오기
         *
         */

        Comment comment = new Comment();
        comment.setBoard_no(request.getParameter("boardno"));
        comment.setComment_db_name("BETTERSOFTPORTAL_NOTICE_BOARD_COMMENT");
        comment.setActivate_yn("Y");

        java.util.List commentList = commentService.getCommentListByBoardNo(comment);
        String commentCount = commentService.getTotalCountByNo(comment);


        request.setAttribute("param", request);
        request.setAttribute("totalRow", totalCount);
        request.setAttribute("currentPage", (new StringBuilder()).append(board.getCurrentPage()).append("").toString());
        request.setAttribute("pageSize", (new StringBuilder()).append(board.getPageSize()).append("").toString());

        request.setAttribute("commentCount", commentCount);

        ModelAndView mav = new ModelAndView();
        mav.setViewName(request.getParameter("nextTarget"));
        mav.addObject("board", tempBoard);
        mav.addObject("boardList", boardList);
        mav.addObject("commentList", commentList);
        return mav;
    }

    

    




    ///////////////////////////////////////
    // Spring Framework Setter Injection //
    ///////////////////////////////////////

}
